package com.biz.primus.ms.auth.api;

import com.biz.primus.model.sso.auth.vo.MenusRegisterReqVO;
import com.biz.primus.model.sso.auth.vo.UserAuthoritiesResVO;
import com.biz.primus.ms.auth.service.AuthorityService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by younger on 17/11/6.
 */
@RestController
@RequestMapping("soa/authorityService")
public class AuthorityApiController {

    private final AuthorityService authorityService;

    @Autowired
    public AuthorityApiController(AuthorityService authorityService){
        this.authorityService = authorityService;
    }

    @ApiOperation("拿到当前用户的用户权限")
    @PostMapping("getUserAuthorities")
    public UserAuthoritiesResVO getUserAuthorities(@RequestParam(name = "userUnionId") String userUnionId){
        return authorityService.getUserAuthorities(userUnionId);
    }

    @ApiOperation("设置服务器模块上报菜单及权限")
    @PostMapping("authorityRegister")
    public void authorityRegister(@RequestBody MenusRegisterReqVO reqVO){
        authorityService.authorityRegister(reqVO);
    }


    @ApiOperation("通过userUnionId得到用户权限信息")
    @GetMapping("listUserMenusAndGrantedAuthorities")
    public UserAuthoritiesResVO listUserMenusAndGrantedAuthorities(@RequestParam(name = "userUnionId") String userUnionId){
        UserAuthoritiesResVO userAuthoritiesResVO = authorityService.getUserAuthorities(userUnionId);
        return userAuthoritiesResVO;
    }
}
